<template>
  <Dialog
    :title="t('scxFinalCandidate.judgeConfirm.title')"
    v-model="dialogVisible"
    width="900"
    :fullscreen="false"
  >
    <!-- 列表 -->
    <ContentWrap>
      <vxe-table
        id="iScxFinalJudgeConfirmList-table"
        v-loading="loading"
        :data="list"
        stripe
        :row-config="{ keyField: 'id' }"
        :custom-config="vxeTableConfig"
        :column-config="{ resizable: true }"
        :size="vxeTableSize"
      >
        <vxe-column :title="t('common.index')" type="seq" field="seq" width="60" align="center" />
        <vxe-column
          :title="t('scxFinalCandidate.judgeConfirm.mentorName')"
          field="mentorName"
          align="center"
          show-header-overflow
          show-overflow
          min-width="100"
        />
        <vxe-column
          :title="t('scxFinalCandidate.judgeConfirm.mentorCode')"
          field="mentorCode"
          align="center"
          show-header-overflow
          show-overflow
          min-width="100"
        />
        <vxe-column
          :title="t('scxFinalCandidate.judgeConfirm.confirmResult')"
          field="confirmResult"
          align="center"
          show-header-overflow
          show-overflow
          min-width="100"
        >
          <template #default="scope">
            <span v-if="scope.row.confirmResult">{{ t('judgeScene.initial.confirmed') }}</span>
            <span v-else>{{ t('judgeScene.initial.unconfirmed') }}</span>
          </template>
        </vxe-column>
      </vxe-table>
      <!-- 分页 -->
      <Pagination
        :total="total"
        v-model:page="queryParams.pageNo"
        v-model:limit="queryParams.pageSize"
        @pagination="getList"
      />
    </ContentWrap>
  </Dialog>
</template>

<script setup lang="ts">
import type { VxeTablePropTypes } from 'vxe-table'
import { useAppStore } from '@/store/modules/app'
import { JudgesSubmitResVO, ReviewSceneApi } from '@/api/awards/reviewscene'

/** 确认获奖名单评委列表 */
defineOptions({ name: 'ScxFinalJudgeConfirmList' })

const message = useMessage() // 消息弹窗
const { t } = useI18n() // 国际化

const dialogVisible = ref(false)

const loading = ref(true) // 列表的加载中
const list = ref<JudgesSubmitResVO[]>([]) // 列表的数据
const total = ref(0) // 列表的总页数
const queryParams = reactive({
  pageNo: 1,
  pageSize: 10,
  awardsInstanceId: undefined,
  roundId: undefined
})
const queryFormRef = ref() // 搜索的表单
const exportLoading = ref(false) // 导出的加载中

const vxeTableConfig: VxeTablePropTypes.CustomConfig = {
  storage: true,
  mode: 'drawer',
  checkMethod({ column }) {
    return !['seq', 'operator'].includes(column.field)
  }
}

const appStore = useAppStore()
const vxeTableSize = computed(() => appStore.getCurrentSizeVxe)

const reset = () => {
  queryParams.pageNo = 1
  queryParams.pageSize = 10
  list.value = []
  total.value = 0
}

const open = (awardsId: string, roundId: string) => {
  dialogVisible.value = true
  reset()
  queryParams.awardsInstanceId = awardsId as any
  queryParams.roundId = roundId as any
  getList()
}

/** 查询列表 */
const getList = async () => {
  loading.value = true
  try {
    const data = await ReviewSceneApi.getJudgesResults(queryParams)
    list.value = data.list
    total.value = data.total
  } finally {
    loading.value = false
  }
}

defineExpose({ open })
</script>
